#include <ObjBase.h>
#include "plusFactory.h"
#include "plusGuid.h"
long g_nComObjsInUse =0;

HMODULE g_hModule=NULL;

BOOL APIENTRY DllMain( HANDLE _HDllHandle,  DWORD _Reason,  LPVOID _Reserved)
{
	if (_Reason == DLL_PROCESS_ATTACH)
	{
		g_hModule = (HMODULE)_HDllHandle;
	}
	return TRUE;
}

STDAPI DllGetClassObject(const CLSID& clsid,
						 const IID& iid,
						 void** ppv)
{
	//
	//Check if the requested COM object is implemented in this DLL
	//There can be more than 1 COM object implemented in a DLL
	//

	if (clsid == CLSID_PlusObject)
	{
		//
		//iid specifies the requested interface for the factory object
		//The client can request for IUnknown, IClassFactory,
		//IClassFactory2
		//
		CAddFactory *pAddFact = new CAddFactory;
		if (pAddFact == NULL)
			return E_OUTOFMEMORY;
		else
		{
			return pAddFact->QueryInterface(iid , ppv);
		}
	}


	//
	//if control reaches here then that implies that the object
	//specified by the user is not implemented in this DLL
	//

	return CLASS_E_CLASSNOTAVAILABLE;
}



///////////////////////////////////////////////////////////////////////////////

STDAPI DllCanUnloadNow()
{
	
	if (g_nComObjsInUse == 0)
	{
		return S_OK;
	}
	else
	{
		return S_FALSE;
	}

}
